{extend name="admin/b2c/base" /}
{block name="resources"/}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/product.css">
<style type="text/css">
.fun-a {
	margin-top: 0px;
	padding: 6px 15px 0 15px;
}
.style0list tbody td a{
	margin-left: 8px;
}
.num{width:40px;text-align:center;}	
.cell_total{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;width:250px;display: block;}
.style0list table input {
	margin-bottom: 0px;
}

.style0list table input.sort {
	width: auto;
	text-align: center;
}

.style0list tbody td {
	line-height: 28px;
}
</style>
{/block}
{block name="right_tab"}
<li><a class="nscs-table-handle_green" href="ADMIN_MAIN/Cms/addArticle.html" ><i class="fa fa-plus-circle"></i>&nbsp;添加文章</a></li>
{/block}
{block name="main"}
<div class="mod-table">
	<div class="con style0list">
		<table>
			 <colgroup>
				<col style="width: 1%">
				<col style="width: 5%;">
				<col style="width: 25%;">
				<col style="width: 7%;">
				<col style="width: 10%;">
				<col style="width: 14%;">
				<col style="width: 5%;">
				<col style="width: 12%;">
			</colgroup>
			<thead>
				<tr align="center">
					<th><label><input id="ckall" type="checkbox" onClick="CheckAll(event)"></label></th>
					<th class="x-tab"><div class="iconbg-arrow up">排序</div></th>
					<th class="x-tab"><div class="iconbg-arrow up">标题</div></th>
					<th class="x-tab"><div class="iconbg-arrow up">分类</div></th>
					<th class="x-tab"><div class="iconbg-arrow up">点击量 / 评论量</div></th>
					<th class="x-tab"><div class="iconbg-arrow up">发布时间</div></th>
					<th class="x-tab"><div class="iconbg-arrow up">状态</div></th>
					<th class="x-tab">操作</th>
				</tr>
			</thead>
			<tbody></tbody>
		</table>
	</div>
</div>
{/block}
{block name="script"}
{include file="admin/b2c/pageCommon" /}
{include file="admin/b2c/openDialog" /}
<script type="text/javascript">
//分页数据
function LoadingInfo(pageIndex) {
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "ADMIN_MAIN/Cms/articleList",
		async : true,
		data : {
			"pageIndex" : pageIndex, "search_text" : search_text
		},
		success : function(data) {
			//alert(JSON.stringify(data));
			$("#page_count").val(data["page_count"]);
			$("#pageNumber a").remove();
			var html = '';
			if (data["data"].length > 0) {
				for (var i = 0; i < data["data"].length; i++) {
					html += '<tr align="center">';
					html += '<td><div class="cell"><label ><input name="sub" type="checkbox" value="'+ data['data'][i]['article_id']+'" ></label></div></td>';
					html += '<td><input type="number" min="0" value="'+ data["data"][i]["sort"]+'"  fieldid="'+ data['data'][i]['article_id']+'" class="num" ></td>';	
					html += '<td class="cell_total" title="'+data["data"][i]["title"]+'">' + data["data"][i]["title"]+ '</td>';
					html += '<td>' + data["data"][i]["name"]+ '</td>';
					html += '<td>' + data["data"][i]["click"]+ ' / ' + data["data"][i]["comment_count"]+ '</td>';
					html += '<td>' + data["data"][i]["create_time"]+ '</td>';
					if(data["data"][i]["status"]==0){
						html += '<td>草稿</td>';	
					}else if(data["data"][i]["status"]==1){ 
						html += '<td>待审核</td>';
					}else if(data["data"][i]["status"]==2){ 
						html += '<td>已发布</td>';
					}else if(data["data"][i]["status"]==-1){ 
						html += '<td>回收站</td>';
					}
					html += '<td><a target="_blank" href="SHOP_MAIN/cms/articleClassInfo.html?article_id='+ data['data'][i]['article_id']+'&class_id='+data["data"][i]["class_id"]+'">预览</a><a href="ADMIN_MAIN/Cms/updateArticle.html?id='+ data['data'][i]['article_id']+'">修改</a><a style="cursor: pointer;" onclick="deleteArticle('+data['data'][i]['article_id']+')">删除</a></td> ';
					html += '</tr>';
				}
			} else {
				html += '<tr align="center"><th colspan="9">暂无文章</th></tr>';
			}
			$(".style0list tbody").html(html);
			var totalpage = $("#page_count").val();
			if (totalpage == 1) {
				changeClass("all");
			}
			var $html = pagenumShow(jumpNumber,totalpage,{$pageshow})
			$("#pageNumber").append($html);
			load();
		}
	});
}	

var flag = false;
//删除分类
function deleteArticle(article_id){
	$( "#dialog" ).dialog({
		buttons: {
			"确定,#e57373": function() {
				$(this).dialog('close');
				if(!flag){
					flag = true;
					$.ajax({
						type : "post",
						url : "ADMIN_MAIN/Cms/deleteArticle",
						async : true,
						data : {
							"article_id" : article_id
						},
						dataType : "json",
						success : function(data) {
							if (data["code"] > 0) {
								showMessage('success', data["message"]);
								LoadingInfo(1);
							}else{
								showMessage('error', data["message"]);
							}
							flag = false;
						}
					})
				}
			},
			"取消": function() {
				$(this).dialog('close');
			}
		},
	contentText:"是否删除文章？",
	});
}

/*修改排序*/
function load(){
	$('.num').change(function(){
		var fieldid = $(this).attr('fieldid');
		var sort = $(this).val();
		$.ajax({
			type:"post",
			url:"ADMIN_MAIN/Cms/modifyArticleField",
			data:{'fieldid':fieldid,'sort':sort},
			async:true,
			success: function (data) {
				if(data['code'] <= 0){
					showMessage('error', data["message"]);
				}
			}
		});
	});
}
</script>
{/block}